package com.SAndR.music;

import android.media.Image;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.SAndR.music.adapter.WelcomeAdapter;
import com.SAndR.music.fragment.OneFragment;
import com.SAndR.music.fragment.TwoFragment;
import com.SAndR.music.fragment.WelcomeFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 引导页
 */

public class WelcomeActivity extends AppCompatActivity {

    private ViewPager vp;
    private LinearLayout ll;

    List<Fragment> fragmentList;
    List<ImageView> imageViewList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        vp = (ViewPager) findViewById(R.id.vp);
        ll = (LinearLayout) findViewById(R.id.ll);

        fragmentList = new ArrayList<>();
        fragmentList.add(new OneFragment());
        fragmentList.add(new TwoFragment());
        fragmentList.add(new WelcomeFragment());v c    ++

        WelcomeAdapter welcomeAdapter = new WelcomeAdapter(getSupportFragmentManager(),fragmentList);

        vp.setAdapter(welcomeAdapter);

        imageViewList = new ArrayList<>();
        for (int i = 0; i < fragmentList.size(); i++) {
            ImageView imageView = new ImageView(this);
            if (i == 0){
                imageView.setImageResource(R.drawable.circle_t);
            }else
            imageView.setImageResource(R.drawable.circle);
            imageViewList.add(imageView);

            ll.addView(imageView);
        }

        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                for (int j = 0; j < imageViewList.size(); j++) {
                    if (j == i){
                        imageViewList.get(j).setImageResource(R.drawable.circle_t);
                    }else {
                        imageViewList.get(j).setImageResource(R.drawable.circle);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }
}
